#include <fstream>
#include <iostream>
#include <iomanip>
#include "TFile.h"
#include "TTree.h"
#include "TLine.h"
#include "TSystem.h"
#include "TLegend.h"
#include "TLegendEntry.h"
#include "TH1.h"
#include "TH2.h"
#include "TMath.h"
#include "TCanvas.h"
#include "TGraph.h"
#include "TRandom.h"

using namespace std;

void Test(){

  TH1F *hcos = new TH1F("hcos","hcos",1000,-1,1);
  TH1F *hangle = new TH1F("hangle","hangle",180,0,180);

  double cos;
  double angle;

  for(int i=0;i<1000;i++){
    hcos->SetBinContent(i+1,1);
  }

  for(int i=0;i<10000000;i++){
    cos = 1-2*gRandom->Rndm();
    angle = acos(cos)*(180./TMath::Pi());
    if(cos > -0.5 && cos < 0.5){
      hangle->Fill(angle);
    }
  }

  TCanvas *c = new TCanvas("c","c",1200,600);
  c->Divide(2,1);
  c->cd(1);
  hcos->Draw();
  c->cd(2);
  hangle->Draw();

  double peak = hangle->GetMaximum();
  hangle->Scale(1./peak);

  TFile *fout = new TFile("TestDist.root","recreate");
  hangle->Write();

}
